<%@ page language="java" pageEncoding="UTF-8" %>
<%@ page import="com.ncr.teradata.bireport.*" %>
<%@ page import="ChartDirector.*" %>
<%@ page import="java.util.List" %>
<%@ page import="java.math.BigDecimal" %>
<%@ page import="java.util.Enumeration" %>
<%@ page import="com.telecom.cms.dto.SysUser" %>
<%
	String cityCode = "1000";
	String countryCode = "";
	
	String campId = "";
	String campSeqId = "";
	String minDateId = "";
	String maxDateId = "";
	Enumeration e = request.getParameterNames();
	while (e.hasMoreElements())
	{
		String hdName = (String)e.nextElement();
		if (hdName.equals("campId"))
			campId = request.getParameter(hdName);
		if (hdName.equals("campSeqId"))
			campSeqId = request.getParameter(hdName);
		if (hdName.equals("minDateId"))
			minDateId = request.getParameter(hdName);
		if (hdName.equals("maxDateId"))
			maxDateId = request.getParameter(hdName);
	}
	
	Report report = new Report("CAMP_CONT_RSLT",cityCode,countryCode);
	SysUser user = (SysUser)request.getSession().getAttribute("User_Inst");
	if (user.getUserRole().equals(com.telecom.cms.util.Constant.getStPara("TeamLdRoleId")))
		report.addFilter("Team_Id",new String[]{String.valueOf(user.getTeamId())});
	if (user.getUserRole().equals(com.telecom.cms.util.Constant.getStPara("CallerRoleId")))
		report.addFilter("User_Id",new String[]{String.valueOf(user.getUserId())});
	if(!campId.equals(""))
		report.addFilter("Camp_Id",new String[]{campId});
	if(!campSeqId.equals(""))
		report.addFilter("Camp_Seq_Id",new String[]{campSeqId});
	if(!minDateId.equals("") && !maxDateId.equals(""))
		report.addFilter("Date_Id",new String[]{Report.BETWEEN,minDateId,maxDateId});
	report.addDimension(new String[]{"Camp_Cont_Rslt_Name"});
	report.addMeasure(new String[]{"Rslt_Count"});
	List reportData = report.buildData();
	
	String[] chartLabels = new String[reportData.size() > 0 ? reportData.size() : 0];
	double[][] chartDatas = new double[1][reportData.size() > 0 ? reportData.size() : 0];
	int idx = -1;
	for (int i = 0; i < reportData.size(); i++){
		idx ++;
		Object[] row = (Object[])reportData.get(i); 
		chartLabels[idx] = (String)row[0];
		chartDatas[0][idx] = ((BigDecimal)row[1]).doubleValue();
	}
	XYChart chart = new XYChart(515, 300);
	chart.setDefaultFonts("??","Bold");
	chart.setPlotArea(40, 10, 470, 120);
	LineLayer lineLayer = chart.addLineLayer();
	lineLayer.setLineWidth(2);
	BarLayer barLayer = chart.addBarLayer(Chart.Side);
	barLayer.addDataSet(chartDatas[0], 0x8080ff, "<*font=??*>用户数<*/*>");
	//chart.yAxis().setTitle("用户数").setFontSize(9);
	chart.xAxis().setLabels(chartLabels).setFontAngle(90);
	chart.xAxis().setLabels(chartLabels).setFontSize(9);
	String chartURL = chart.makeSession(request, "prom_eva_dep_month_chart");
	String imageMap = chart.getHTMLImageMap("", "","title='{xLabel} {dataSetName} : {value}'");
	
	Report pieReport = new Report("CAMP_CONT_RSLT",cityCode,countryCode);
	if (user.getUserRole().equals(com.telecom.cms.util.Constant.getStPara("TeamLdRoleId")))
		pieReport.addFilter("Team_Id",new String[]{String.valueOf(user.getTeamId())});
	if (user.getUserRole().equals(com.telecom.cms.util.Constant.getStPara("CallerRoleId")))
		pieReport.addFilter("User_Id",new String[]{String.valueOf(user.getUserId())});
	if(!campId.equals(""))
		pieReport.addFilter("Camp_Id",new String[]{campId});
	if(!campSeqId.equals(""))
		pieReport.addFilter("Camp_Seq_Id",new String[]{campSeqId});
	if(!minDateId.equals("") && !maxDateId.equals(""))
		pieReport.addFilter("Date_Id",new String[]{Report.BETWEEN,minDateId,maxDateId});
	pieReport.addDimension(new String[]{"Camp_Cont_Rslt_Lvl1_Name"});
	pieReport.addMeasure(new String[]{"Rslt_Count"});
	List pieReportData = pieReport.buildData();
	
	chartLabels = new String[pieReportData.size() > 0 ? pieReportData.size() : 0];
	chartDatas = new double[1][pieReportData.size() > 0 ? pieReportData.size() : 0];
	idx = -1;
	for (int i = 0; i < pieReportData.size(); i++){
		idx ++;
		Object[] row = (Object[])pieReportData.get(i); 
		chartLabels[idx] = (String)row[0];
		chartDatas[0][idx] = ((BigDecimal)row[1]).doubleValue();
	}
	
	PieChart chart2 = new PieChart(515, 200);
	chart2.setPieSize(260, 95, 90);
	chart2.setDefaultFonts("??","Bold");
	chart2.setLineColor(0xffffff);
	chart2.set3D();
	//chart2.setLabelStyle().setBackground(0xffffc0, 0x0);
	chart2.setLabelStyle().setFontSize(9);
	//chart2.setLabelLayout(Chart.CircleLayout, -2);
	chart2.setLabelLayout(Chart.SideLayout);
	TextBox t = chart2.setLabelStyle();
	t.setBackground(Chart.SameAsMainColor, Chart.Transparent, Chart.glassEffect());
	t.setRoundedCorners(5);
	chart2.setData(chartDatas[0], chartLabels);
	//chart2.setColors2(Chart.DataColor, new int[]{0xff3333, 0xff6666,0xff9999, 0xffaaaa,0xffcccc});
	String chartURL2 = chart2.makeSession(request, "camp_audit_cont_rslt_pie");
	String imageMap2 = chart2.getHTMLImageMap("","","title='{label}: {value}户 （{percent}%）'");
	
	Report rankReport = new Report("CAMP_KPI_AUDIT",cityCode,countryCode);
	if (user.getUserRole().equals(com.telecom.cms.util.Constant.getStPara("TeamLdRoleId")))
		rankReport.addFilter("Team_Id",new String[]{String.valueOf(user.getTeamId())});
	if (user.getUserRole().equals(com.telecom.cms.util.Constant.getStPara("CallerRoleId")))
		rankReport.addFilter("User_Id",new String[]{String.valueOf(user.getUserId())});
	if(!campId.equals(""))
		rankReport.addFilter("Camp_Id",new String[]{campId});
	if(!campSeqId.equals(""))
		rankReport.addFilter("Camp_Seq_Id",new String[]{campSeqId});
	if(!minDateId.equals("") && !maxDateId.equals(""))
		rankReport.addFilter("Date_Id",new String[]{Report.BETWEEN,minDateId,maxDateId});
	rankReport.addDimension(new String[]{"User_Name"});
	rankReport.addMeasure(new String[]{"Accp_Total"});
	rankReport.addDeriveMeasure("受理率排名",Report.RANKING,new String[]{"Accp_Total"});
	List rankReportData = rankReport.buildData();
%>

<html>
<head>
	<title>营销监控</title>
	<link href="../css/style.css" rel="stylesheet" type="text/css"/>
    <link href="../css/font.css" rel="stylesheet" type="text/css">
</head>
<body>
	<table width="100%" height="100%"  border="0" align="center" cellpadding="0" cellspacing="1" >
		<tr>
			<td valign='top' align='left' bgcolor="#FFFFFF"> 
				<table border=0 width="100%" class="tablestyle4" style='table-layout:' cellspacing='1' cellpadding='0' bordercolordark='#ffffff' bordercolorlight='#ffffff'>
					<tr class="fontblue" width="100%" align="left">
						<td align='left' valign='center'>
							<img src="../images/title_left.gif" width="10" height="10">
                    		接触结果分析：
                    	</td>
                        <td align="right" valign='center'>
                        	<img src="../images/title_left.gif" width="10" height="10">
                        	<a href='camp_audit_cont_detail.jsp?campId=<%= campId %>&campSeqId=<%= campSeqId %>&minDateId=<%= minDateId %>&maxDateId=<%= maxDateId %>' target="_blank" style='text-decoration:none;color:blue'>详情进入</a>
                        </td>
					</tr>
				</table>
				<table border=1 width=100% class="style4" style='table-layout:' cellspacing='0' cellpadding='0' bordercolordark='#FFFFFF' bordercolorlight='#FFFFFF'>
					<tr align="left">
						<td width="100%">
							<img src='<%= response.encodeURL("getchart.jsp?"+chartURL2) %>' usemap="#map2" border="0">
							<map name="map2"><%= imageMap2 %></map>
						</td>
					</tr>
				</table>
				<table border=1 width=100% class="style4" style='table-layout:' cellspacing='0' cellpadding='0' bordercolordark='#FFFFFF' bordercolorlight='#FFFFFF'>
					<tr align="left">
						<td width="100%">
							<img src='<%= response.encodeURL("getchart.jsp?"+chartURL) %>' usemap="#map" border="0">
							<map name="map"><%= imageMap %></map>
						</td>
					</tr>
				</table>
				<table border=0 width="100%" class="tablestyle4" style='table-layout:' cellspacing='1' cellpadding='0' bordercolordark='#ffffff' bordercolorlight='#ffffff'>
					<tr class="fontblue" width="100%" align="left">
						<td align='left' valign='center'>
							<img src="../images/title_left.gif" width="10" height="10">
                    		员工受理量排名：
                    	</td>
                        <td align="right" valign='center'>
                        	<img src="../images/title_left.gif" width="10" height="10">
                        	<a href='#' style='text-decoration:none;color:blue'>详情进入</a>
                        </td>
					</tr>
				</table>
				<table border=0 width=100% class="tablestyle4" style='table-layout:fixed' cellspacing='0' cellpadding='0' bordercolordark='#ccffff' bordercolorlight='#9999cc'>
					<tr align="center" valign='top'>
						<td width='25%'>
							<table border=1 width=100% class="tablestyle1" style='table-layout:fixed' cellspacing='0' cellpadding='0' bordercolordark='#ccffff' bordercolorlight='#9999cc'>
								<tr align="center">
									<td colspan="2">最佳</td>
								</tr>
								<tr align="center">
									<td>姓名</td><td>受理数</td>
								</tr>
								<%
									for(int i = 0; i < rankReportData.size(); i++) {
										if (i >= 5)
											break;
										for (int j = 0; j < rankReportData.size(); j++){
											Object[] row = (Object[])rankReportData.get(j); 
											if (((BigDecimal)row[2]).intValue() == i + 1){
								%>
								<tr align="center">
									<TD><%= (String)row[0] %></TD>
									<TD><%= (BigDecimal)row[1] %></TD>
								</tr>
								<% break;}}} %>
							</table>
						</td>
						<td width='25%'>
							<table border=1 width=100% class="tablestyle1" style='table-layout:fixed' cellspacing='0' cellpadding='0' bordercolordark='#ccffff' bordercolorlight='#9999cc'>
								<tr align="center">
									<td colspan="2">最差</td>
								</tr>
								<tr align="center">
									<td>姓名</td><td>受理数</td>
								</tr>
								<%
									for(int i = 0; i < rankReportData.size(); i++) {
										if (i >= 5)
											break;
										for (int j = 0; j < rankReportData.size(); j++){
											Object[] row = (Object[])rankReportData.get(j); 
											if (((BigDecimal)row[2]).intValue() == rankReportData.size() - i){
								%>
								<tr align="center">
									<TD><%= (String)row[0] %></TD>
									<TD><%= (BigDecimal)row[1] %></TD>
								</tr>
								<% break;}}} %>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</body>
</html>


